package edu.hawaii.duedates.webApp;

import org.apache.wicket.Page;
import org.apache.wicket.Request;
import org.apache.wicket.Response;
import org.apache.wicket.Session;
import org.apache.wicket.protocol.http.WebApplication;
import edu.hawaii.duedates.configuration.ConfigurationManager;
import edu.hawaii.duedates.configuration.DueDatesConfiguration;

/**
 * Application object for the DueDates Web Application. 
 * Class extends WebApplication.
 * 
 * @author Tyler Wolff
 */
public class DueDatesApplication extends WebApplication {

  private final DueDatesConfiguration config;
  
  /**
   * Indicate that Index is the home page for this application.
   * @return The home page, which is Index.
   */
  @Override
  public Class<? extends Page> getHomePage() {
    return Index.class;
  }
  
  /**
   * Return a session object to hold the models for each user of this application.
   * 
   * @param request The http request.
   * @param response The http response. 
   * @return The session instance for this user. 
   */
  @Override
  public Session newSession(Request request, Response response) {
    DueDatesSession newSession = new DueDatesSession(request);
    newSession.setDueDatesConfiguration(this.config);    
    return newSession;
  }
  
  /**
   * The default constructor for a DueDatesApplication.
   */
  public DueDatesApplication() {
    ConfigurationManager cm = new ConfigurationManager();
    this.config = cm.getDueDates();
  }
  
  /**
   * A constructor for starting the application without reading from .duedates/duedates.xml.
   * The application is started with a specified configuration object.
   * 
   * @param config A DueDatesConfiguration object.
   */
  public DueDatesApplication(DueDatesConfiguration config) {
    this.config = config;
  }
}
